module.exports = function ($scope, $resource, $stateParams, $modal, toaster, $timeout) {

    $scope.allSaleList = [];
    $scope.viewMap = {};
    //搜索信息
    $scope.pageInfo = {};
    $scope.loadDate = function () {
        $resource('/api/as/ggc/activity/activityList', {}, {}).save($scope.pageInfo, function (res) {
            if (res.errcode === 0) {
                $scope.saleList = res.data;
            } else {
                toaster.error({ title: '', body: res.errmsg });
            }
        });
    }
    $scope.loadDate();
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadDate();
		}
	};

    $scope.show_info = function ( index) {
        $scope.saleList[index].is_show_info = !$scope.saleList[index].is_show_info;
    }

    $scope.order_info = {
        'name': '',
        'cardno': '',
        'mobile': '',
        'by_bus': '',
        'note': '',
        'contact_account': '',
        'tour_date': '',
        'order_source': '0'
    };

    //单人下单
    $scope.buy = function (sale, info) {
        // if (info.flag != 1 && info.flag != '1') {
        //     return false;
        // }
        let sale_info = sale;
        Object.assign(sale_info, info);
        var modalInstance = $modal.open({
            template: require('../views/tourCreateOrder.html'),
            controller: 'tourCreateOrder',
            size: 'lg',
            resolve: {
                sale_info: function () {
                    return sale_info;
                }
            }
        });
        modalInstance.result.then(function (result) {
            $scope.order_info = result;
            $scope.loadDate();
        });
    }

    //批量下单
    $scope.buyBatch = function (sale, info) {
        // if (info.flag != 1 && info.flag != '1') {
        //     return false;
        // }
        let sale_info = sale;
        Object.assign(sale_info, info);
        var modalInstance = $modal.open({
            template: require('../views/tourCreateBatchOrder.html'),
            controller: 'tourCreateBatchOrder',
            size: 'lg',
            resolve: {
                sale_info: function () {
                    return sale_info;
                }
            }
        });
        modalInstance.result.then(function (result) {
            $scope.order_info = result;
            $scope.loadDate();
        });
    }
    
	//活动信息
	$scope.info = function (activity) {
		var modalInstance = $modal.open({
			template: require('../views/tourActivityInfo.html'),
			controller: 'tourActivityInfo',
			size: 'lg',
			resolve: {
				activity: function () {
					return activity;
				}
			}
		});
		//关闭模态框刷新页面
		modalInstance.result.then(function () {
			$scope.loadlist();
		});
	}
    
	//活动信息
	$scope.qrcode = function (sale, info) {
        // if (info.flag != 1 && info.flag != '1') {
        //     return false;
        // }
        let qrcode = `https://weshop.tripln.com/views/welfare_2018/my_poster.html?company_code=LW00021&aid=${sale.activity_id}&login_code=${sale.company_code}`;
        var modalInstance = $modal.open({
            template: require('../views/tourQrcode.html'),
            controller: 'tourQrcode',
            size: 'sm',
            resolve: {
                qrcode: function () {
                    return qrcode;
                }
            }
        });
        modalInstance.result.then(function (result) {
            $scope.order_info = result;
            $scope.loadDate();
        });
	}

};